package me.wangcai.trafficpoliceai.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import me.wangcai.trafficpoliceai.mapper.ViolationMapper;
import me.wangcai.trafficpoliceai.model.ResponseInfo;
import me.wangcai.trafficpoliceai.model.entity.Violation;
import me.wangcai.trafficpoliceai.service.IViolationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.HashMap;
import java.util.List;


@Service
public class ViolationServiceImpl extends ServiceImpl<ViolationMapper, Violation> implements IViolationService {
    @Autowired
    private ViolationMapper violationMapper;

    @Override
    public ResponseInfo add(Violation violation) {
        violation.setTime(LocalDate.now());
        violationMapper.insert(violation);
        return ResponseInfo.success("添加成功");
    }

    @Override
    public ResponseInfo filterViolation(HashMap<String, String> filterMap) {
        QueryWrapper<Violation> wrapper = Wrappers.query();
        filterMap.forEach((k,v) -> {
            wrapper.like(k,v);
        });
        List<Violation> list = violationMapper.selectList(wrapper);
        return ResponseInfo.success("查询成功",list);
    }


//    @Override
//    public ResponseInfo updateViolation(Integer id, String username) {
//        User user=userMapper.selectOne(new QueryWrapper<User>().eq("username", username));
//        Violation violation=new Violation(id,user.getUsername(), LocalDate.now());
//        int a=violationMapper.updateById(violation);
//        int b=violationMapper.deleteById(id);
//        if(a>1&&b>1){
//            return ResponseInfo.success("执行失败");
//        }
//        return ResponseInfo.success("执行成功");
//    }
}